<?php
//--------------------------------------------------------------------------------
// Copyright 2003 Procata, Inc.
// Released under the LGPL license (http://www.gnu.org/copyleft/lesser.html)
//--------------------------------------------------------------------------------
/**
* @package WACT_TAG
* @version $Id: form.tag.php,v 1.24 2004/11/18 04:22:48 jeffmoore Exp $
*/

/**
* Register the tag
*/
$taginfo =& new TagInfo('form', 'FormTag');
$taginfo->setCompilerAttributes(array('useknown'));
$taginfo->setDefaultLocation(LOCATION_CLIENT);
TagDictionary::registerTag($taginfo, __FILE__);

/**
* Compile time component for building runtime FormComponents
* @see http://wact.sourceforge.net/index.php/FormTag
* @access protected
* @package WACT_TAG
*/
class FormTag extends ServerTagComponentTag {
	/**
	* File to include at runtime
	* @var string path to runtime component relative to WACT_ROOT
	* @access private
	*/
	var $runtimeIncludeFile = '/template/components/form/form.inc.php';
	/**
	* Name of runtime component class
	* @var string
	* @access private
	*/
	var $runtimeComponentName = 'FormComponent';


	/**
	* Returns the identifying server ID. It's value it determined in the
	* following order;
	* <ol>
	* <li>The XML id attribute in the template if it exists</li>
	* <li>The XML name attribute in the template if it exists</li>
	* <li>The value of $this->ServerId</li>
	* <li>An ID generated by the getNewServerId() function</li>
	* </ol>
	* @see getNewServerId
	* @return string value identifying this component
	* @access protected
	*/
	function getServerId() {
		if ($this->hasAttribute('id')) {
			return $this->getAttribute('id');
		} else if ($this->hasAttribute('name')) {
			return $this->getAttribute('name');
		} else if (!empty($this->ServerId)) {
			return $this->ServerId;
		} else {
			$this->ServerId = getNewServerId();
			return $this->ServerId;
		}
	}

	/**
	* @return void
	* @access protected
	*/
	function CheckNestingLevel() {
		if ($this->findParentByClass('FormTag')) {
            RaiseError('compiler', 'BADSELFNESTING', array(
                'tag' => $this->tag,
                'file' => $this->SourceFile,
                'line' => $this->StartingLineNo));
		}
	}

	/**
	* @param CodeWriter
	* @return void
	* @access protected
	*/
	function preGenerate(&$code) {
		$code->writePHP($this->getComponentRefCode() . '->prepare();');
		parent::preGenerate($code);
		$code->writePHP($this->getComponentRefCode() . '->renderState();');
	}

	/**
	* @return FormTag this instance
	* @access protected
	*/
	function &getDataSource() {
		return $this;
	}

	/**
	* @return string PHP runtime reference to object
	* @access protected
	*/
	function getDataSourceRefCode() {
        return $this->getComponentRefCode() . '->_datasource';
	}
	
	/**
	* @return Boolean Indicating whether or not this component is a DataSource
	*/
	function isDataSource() {
	    return TRUE;
	}
}
?>
